package com.share;

import hipro.entities.Country;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.SharedPreferences;
import android.os.Bundle;

public class CountryActivity  extends BaseActivity{
	private String username;
	private String password;
	private hipro.country.Country webserviceCountry;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.event_list);

		// set view events
		webserviceCountry = new hipro.country.Country();
		webserviceCountry.setWebservice(getString(R.string.webservice_country));

		this.setValueAccount();
		this.showCountry();
		//this.getCountry();
	}
	
	private void getCountry(){
		hipro.entities.Country country = new Country();
		country = webserviceCountry.getCountry(this.username, this.password, 1);
		
		AlertDialog al = new AlertDialog.Builder(this).create();
		al.setMessage(country.getName());
		al.show();
	}
	
	private void showCountry(){
		String  str = "";
		ArrayList<hipro.entities.Country> list  = 
			new ArrayList<hipro.entities.Country>();
		list = webserviceCountry.getList(this.username, this.password);
		for(hipro.entities.Country country : list){
			str += country.getName();
		}
		AlertDialog al = new AlertDialog.Builder(this).create();
		al.setMessage(str);
		al.show();
	}
	
	/**
	 * Set value account login
	 */
	private void setValueAccount() {
		SharedPreferences settings = getSharedPreferences("pref_login", 0);
		this.username = settings.getString("username", "");
		this.password = settings.getString("password", "");

	}
}
